import 'package:flutter/material.dart';
import 'package:flutter_wan_android/data/user/user_repository.dart';
import 'package:flutter_wan_android/feature/main_screen.dart';
import 'package:flutter_wan_android/feature/user/login_screen.dart';
import 'package:flutter_wan_android/feature/user/login_view_model.dart';
import 'package:flutter_wan_android/feature/user/register_screen.dart';
import 'package:flutter_wan_android/feature/user/register_view_model.dart';
import 'package:provider/provider.dart';

abstract final class AppPages {
  static final String home = "/";
  static final String login = "/login";
  static final String register = "/register";
}

class AppRouter {
  static String initialRoute = AppPages.home;

  static final Map<String, WidgetBuilder> routes = {
    AppPages.home: (context) => const MainScreen(),
    AppPages.login:
        (context) => ChangeNotifierProvider(
          create: (context) => LoginViewModel(
            context.read<UserRepository>()
          ),
          child: const LoginScreen(),
        ),
    AppPages.register: (context) => ChangeNotifierProvider(
      create: (context) => RegisterViewModel(
          context.read<UserRepository>()
      ),
      child: const RegisterScreen(),
    ),
  };

  static Route<dynamic> onGenerateRoute(RouteSettings settings) {
    return MaterialPageRoute(builder: (_) => const UnknownPage());
  }
}

class UnknownPage extends StatelessWidget {
  const UnknownPage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(body: Center(child: Text('404 - Page Not Found')));
  }
}
